package com.home.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.home.common.Cache;
import com.home.model.Area;
import com.home.service.AreaService;

@Controller
public class AreaAction {
	@Autowired
	private AreaService areaService;

	public AreaService getAreaService() {
		return areaService;
	}

	public void setAreaService(AreaService areaService) {
		this.areaService = areaService;
	}
	@RequestMapping("/admin/area/list.do")
	public String getAll(HttpServletRequest request) {
		List<Area> areaList = this.getAreaService().getList();
		request.setAttribute("list", areaList);
		return "/admin/area/list";
	}

	@RequestMapping("/admin/area/save.do")
	public String getAll(Area area) {
		if (area != null) {
			this.getAreaService().save(area);
		}
		Cache.getInstance().refreshArea();
		return "redirect:/admin/area/list.do";
	}

	@RequestMapping("/admin/area/get.do")
	public String getAll(Integer id, HttpServletRequest request) {
		if (id != null) {
			Area area = this.getAreaService().getArea(id);
			request.setAttribute("obj", area);
		}
		return "/admin/area/obj";
	}
	
	
	@RequestMapping("/admin/area/delete.do")
	public String delete(Integer id, HttpServletRequest request) {
		if (id != null) {
			Area area=new Area();
			area.setId(id);
			this.getAreaService().delete(area);
		}
		return "redirect:/admin/area/list.do";
	}
}
